package com.efuture.mutlithread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @ClassNAME TimerThread
 * @Description 该例子用于实现定时器
 * @Author zhaoshanshan
 * @Date 2021/9/11 12:57 下午
 * @Version 1.0
 */
public class TimerThread {

    public static void main(String[] args) {
        Timer t = new Timer();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
             date = sdf.parse("2021-09-11 13:05:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        t.schedule(new LogTimer(),date,1000*10);//每隔10s执行一次定时任务
    }
}
class LogTimer extends TimerTask{

    @Override
    public void run() {
        System.out.println("我是定时任务");
    }
}